package cs429_project;

import java.util.regex.Pattern;

/**
 * A class storing information about the various special marks used in
 * Wikipedia's markup language.  It stores all of the marks that signify
 * disambiguation and redirect pages.
 * @author Peter Ferrans
 */
public class WikiMarks {

    /** All the various disambiguation templates that Wikipedia uses. */
    public static final String[] DIS_MARKS = {"disambig", "Airport disambig",
        "Callsigndis", "Disambig-Chinese-char-title", "Geodis", "Hndis", 
        "Hospitaldis", "Letter disambig", "Letter-NumberCombDisambig",
        "Mathdab", "MolFormDisambig", "Numberdis", "Schooldis", 
        "Species Latin name disambiguation", "Wikipedia disambiguation"};
    /** Identifies a generic disambiguation page. */
    public static final String DISAMBIG = "{{disambig}}";
    /** Identifies a redirect page. */
    public static final String REDIRECT = "#REDIRECT";

    /**
     * Indicates whether the text passed in contains one of Wikipedia's
     * disambiguation marks.
     * @param pageText
     *    Text to be analyzed.
     * @return
     *    Whether or not the text passed in contained a disambiguation mark.
     */
    public static boolean containsDisMark(String pageText) {
        boolean isDisambig = false;
        for(int i = 0; (i < DIS_MARKS.length) && (!isDisambig); i++) {
            Pattern markPattern = Pattern.compile("[^\\w]" +
                    Pattern.quote(DIS_MARKS[i]) + "[^\\w]",
                    Pattern.CASE_INSENSITIVE);
            boolean contains = markPattern.matcher(pageText).find();
            if(contains) {
                isDisambig = true;
            }
        }
        return isDisambig;
    }
}